<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>患者库</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">患者姓名:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入患者姓名" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">手机号:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phone" placeholder="请输入手机号" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">身份证号:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="idNumber" placeholder="请输入身份证号" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="patient-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<!--数据表格-->
<div class="layui-card">
    <div class="layui-card-body">
        <table id="patient-table" lay-filter="patient-table"></table>
    </div>
</div>


<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        let cols = [
            [
                {
                    title: '姓名',
                    field: 'name',
                    align: 'center',
                },
                {
                    title: '联系电话',
                    field: 'phone',
                    align: 'center'
                },
                {
                    title: '身份证号',
                    field: 'idNumber',
                    align: 'center',
                },
                {
                    title: '出生年月',
                    field: 'birthday',
                    align: 'center',
                },
                {
                    title: '年龄',
                    field: 'age',
                    align: 'center',
                },
                {
                    title: '性别',
                    field: 'sex',
                    align: 'center',
                    templet: function (d) {
                        return d.sex == 1 ? '<font>男</font>' : '<font>女</font>';
                    }
                },
                {
                    title: '备注',
                    field: 'remark',
                    align: 'center',
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                }
            ]
        ]

        var tableIns = table.render({
            elem: '#patient-table',
            url: '/patient/loadPatientPage',
            page: true,
            cols: cols,
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print'],
            response: {
                statusCode: 200
            },
            done: function (res, curr, count) {
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            },
        });


        //表格监听
        form.on('submit(patient-query)', function (data) {
            table.reload('patient-table', {
                where: data.field
            })
            return false;
        });


        //表头监听
        table.on('toolbar(patient-table)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
        });


        window.refresh = function (param) {
            table.reload('patient-table');
        }

    })
</script>
</body>
</html>
